$(function(){
    $("#topBtn").click(topPost);
    $("#wonderfulBtn").click(wonderfulPost);
    $("#deleteBtn").click(deletePost);
})

function topPost(){
    var postId = $("input[name='postId']").val();
    $.post(
        CONTEXT_PATH + "/discuss/top",
        {"id": postId},
        function(resp){
            var data = $.parseJSON(resp);
            if (data.code == 200){
                $("#topBtn").attr("disabled", "disabled");
            }else{
                alert(data.msg);
            }
        }
    );
}

function wonderfulPost(){
    var postId = $("input[name='postId']").val();
    $.post(
        CONTEXT_PATH + "/discuss/wonderful",
        {"id": postId},
        function(resp){
            var data = $.parseJSON(resp);
            if (data.code == 200){
                $("#wonderfulBtn").attr("disabled", "disabled");
            }else{
                alert(data.msg);
            }
        }
    );
}

function deletePost(){
    var postId = $("input[name='postId']").val();
    $.post(
        CONTEXT_PATH + "/discuss/delete",
        {"id": postId},
        function(resp){
            var data = $.parseJSON(resp);
            if (data.code == 200){
                location.href = CONTEXT_PATH + "/index";
            }else{
                alert(data.msg);
            }
        }
    );
}